using System.Collections.Generic;
using RimWorld;
using Verse;

public class CompProperties_ImPower : CompProperties
{
    public class ImPowerUpgrade
    {
        public ResearchProjectDef researchProject;

        public float factor;
    }

    public bool transmitsImPower;

    private float baseImPowerConsumption;

    public float idleImPowerDraw = -1f;

    public bool shortCircuitInRain;

    public bool showImPowerNeededIfOff = true;

    public SoundDef soundPowerOn;

    public SoundDef soundPowerOff;

    public SoundDef soundAmbientPowered;

    public SoundDef soundAmbientProducingPower;

    public List<ImPowerUpgrade> ImPowerUpgrades;

    public bool alwaysDisplayAsUsingImPower;

    public float ImPowerConsumption
    {
        get
        {
            float num = baseImPowerConsumption;
            if (Current.ProgramState == ProgramState.Entry)
            {
                return num;
            }
            for (int i = 0; i < ImPowerUpgrades?.Count; i++)
            {
                ResearchProjectDef researchProject = ImPowerUpgrades[i].researchProject;
                if (researchProject != null && researchProject.IsFinished)
                {
                    num *= ImPowerUpgrades[i].factor;
                }
            }
            return num;
        }
    }

    public override IEnumerable<StatDrawEntry> SpecialDisplayStats(StatRequest req)
    {
        foreach (StatDrawEntry item in base.SpecialDisplayStats(req))
        {
            yield return item;
        }
        if (baseImPowerConsumption > 0f)
        {
            yield return new StatDrawEntry(StatCategoryDefOf.Building, "ImPowerConsumption".Translate(), ImPowerConsumption.ToString("F0") + " W", "Stat_Thing_ImPowerConsumption_Desc".Translate(), 5000);
        }
    }
}
